﻿google.load('visualization', '1.0', { 'packages': ['geochart'] });
google.load("visualization", "1", { packages: ["corechart"] });



$(function () {



    var $tree = create_tree({
        layer: "#demo1",
        tree_type_id: var_server.tree_type_id,
        webservice_url: var_server.webservice_url,
        root_folder_id: var_server.root_folder_id,
        icons_path: var_server.icons_path,
        on_select_node: function (e, data) {
            $('#HidSelectFolderId').val(data.rslt.obj.attr("id"));
            $('#BtnReload_UpPEnquiry').click();
            //close_ajax_wait(null);
        },
        on_dnd: function (r) {
            $('#BtnReload_UpPEnquiry').click();
            //close_ajax_wait(null);
        }

    });


    $("#BtnTwitterSearch").click(function () {
        //alert('uuu');
        $.oauthpopup({
            path: 'post_search?q=' + encodeURIComponent($('#TxtTwitterSearch').val()),
            callback: function () {
                //window.$.fancybox.showLoading();
                //window.location.href = 'useraccounts.aspx';
            },
            windowName: "Twitter",
            windowOptions: "location=0,status=0,width=1040,height=600"
        });
    });

    $(document).on("click", "#ChkAllQuery", function () {
        c = $(this).is(':checked');
        //alert(c);
        $('.query_row input:checkbox[id^="ChkItem"]').prop('checked', c);
    });

    $(document).on("click", "#ChkAllProfile", function () {
        c = $(this).is(':checked');
        //alert(c);
        $('.profile_row input:checkbox[id^="ChkItem"]').prop('checked', c);
    });

    $("#add_folder").click(function () {
        $tree.jstree("create", null, "last", {
            attr: {
                rel: this.id.toString().replace("add_", "")
            }
        });
        return false;
    });

    $("#rename_folder").click(function () {
        $tree.jstree("rename");
        return false;

    });

    $("#remove_folder").click(function () {
        $tree.jstree("remove");
    });



});

function DrawChartFollower(o) {

    var data = google.visualization.arrayToDataTable(o.data);

    var options = {
        chartArea: { left: '8%', top: '5%', width: "90%", height: "70%" },
        focusTarget: 'category',
        lineWidth: 3, pointSize: 7, curveType: '',
        hAxis: { slantedText: false, maxAlternation: 1, maxTextLines: 1 },
        vAxis: {},
        series: [
            { color: '#67B203' }
        ],
        legend: { maxLines: 1, position: 'bottom', alignment: 'start' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_div_follower'));
    chart.draw(data, options);

}

function DrawChartPostSend(o) {

    var data = google.visualization.arrayToDataTable(o.data);

    var options = {
        chartArea: { left: '8%', top: '5%', width: "90%", height: "70%" },
        focusTarget: 'category',
        lineWidth: 3, pointSize: 7, curveType: '',
        hAxis: { slantedText: false, maxAlternation: 1, maxTextLines: 1 },
        vAxis: {},
        series: [
            { color: '#29ABE2' }
        ],
        legend: { maxLines: 1, position: 'bottom', alignment: 'start' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_div_follower2'));
    chart.draw(data, options);

}

function draw(o) {

    // create a network
    var container = document.getElementById('mynetwork');
    var data = {
        nodes: o.nodes,
        edges: o.edges
    };
    var options = {
        stabilize: false,
        dragNodes: false,
        configurePhysics: false,
        smoothCurves: false,
        physics: {
            barnesHut: {
                enabled: true,
                gravitationalConstant: -20000,
                centralGravity: 0,
                springLength: 150,
                springConstant: 0.010,
                damping: 0.3
            }
        },
        nodes: {
            radiusMin: 5,
            radiusMax: 15,
            fontSize: 14,
            borderWidth: 1,
            fontColor: '#333333',
            color: {
                background: '#97C2FC',
                border: '#29AAE3',
                highlight: '#C2272D'
            }
        },
        edges: {
            widthMin: 1,
            widthMax: 4,
            color: {
                color: '#dddddd',
                highlight: '#FFD203'
            },
            inheritColor: false
        },
        tooltip: {
            delay: 200,
            fontSize: 12,
            color: {
                background: "#fff"
            }
        },
        groups: {
            level_1: {
                color: {
                    border: '#C1272D',
                    background: '#FBA3A5'

                }
            },
            level_2: {
                color: {
                    border: '#FEB014',
                    background: '#FFFF00'

                }
            },
            level_3: {
                color: {
                    border: '#67B203',
                    background: '#8BD824'

                }
            },
            level_4: {
                color: {
                    border: '#D8D8D8',
                    background: '#ffffff'

                }
            }


        }


    };
    network = new vis.Network(container, data, options);
}



function split(val) {
    return val.split(/ \s*/);
}
function extractLast(term) {
    return split(term).pop();
}

function autoaccount(l, h) {



    $(l).bind("keydown", function (event) {
        if (event.keyCode === $.ui.keyCode.TAB &&
                    $(this).data("ui-autocomplete").menu.active) {
            event.preventDefault();
        }
    }).autocomplete({
        minLength: 0,
        source: function (request, response) {
            PageMethods.set_path('/App/QueryAnalisys.aspx')
            PageMethods.AutoCompleteHashTags(
                        extractLast(request.term),
                        function OnSucceeded(result, usercontext, methodName) {
                            //alert(result);            
                            response(result);
                        });
        },
        focus: function () {
            // prevent value inserted on focus
            return false;
        },
        select: function (event, ui) {
            var terms = split(this.value);
            // remove the current input
            terms.pop();
            // add the selected item
            terms.push(ui.item.value);
            // add placeholder to get the comma-and-space at the end
            terms.push("");
            this.value = terms.join(" ");
            return false;
        }
    });

}

var chk_elab;
function onmousedown_chk_elab(o) {

    c = o.children('input:checkbox')
    chk_elab = c.attr('checked');
    c.attr('checked', true);
    //c.attr('checked', ! c.attr('checked') );
}

function onmouseup_chk_elab(o) {

    c = o.children('input:checkbox')
    c.attr('checked', !chk_elab);
}


